package com.david.func_test.widget

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.david.func_test.R

class QuitTeamDialog(context: Context, var title: String, var onConfirmListener:() -> Unit): Dialog(context) {
    private var ivCheck: ImageView? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.dialog_quit_team)

        findViewById<TextView>(R.id.title).text = "即将退出群聊“$title”"
        findViewById<View>(R.id.cancel_button).setOnClickListener { dismiss() }
        ivCheck = findViewById(R.id.iv_check)
        ivCheck?.setOnClickListener { setIvCheck() }
        findViewById<View>(R.id.content).setOnClickListener { setIvCheck() }
        findViewById<View>(R.id.confirm_button).setOnClickListener{
            onConfirmListener.invoke()
            dismiss()
        }
    }

    private fun setIvCheck(){
        if (ivCheck?.isSelected == true) {
            ivCheck?.setImageResource(R.mipmap.ic_round_unchecked)
            ivCheck?.isSelected = false
        } else {
            ivCheck?.setImageResource(R.mipmap.ic_round_checked)
            ivCheck?.isSelected = true
        }
    }
}